package cc.htdf.gwc.radar.repository.impl;

import cc.htdf.gwc.radar.domain.GridInfo;
import cc.htdf.gwc.radar.repository.StationInfoRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by JT on 2017/11/14.
 */
@Repository
public class StationInfoRepositoryImpl implements StationInfoRepository {

    private static final String TABLE_NAME_RADAR_GRID_INFO = "CONFIG_RADAR_STATION_AROUND_GRID";

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<GridInfo> findGridInfos() {
        String sql = String.format("SELECT STATION_ID AS NEARSTATION, GRID_ID AS GRIDID, LAT AS LAT, LON AS LON FROM %s",
                TABLE_NAME_RADAR_GRID_INFO);
        return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(GridInfo.class));
    }
}
